﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReadyApps.Wiki.ViewModels;

namespace ReadyApps.Data.Wiki
{
    /// <summary>
    /// Contains all the information needed to edit permissions within the wiki system.
    /// </summary>
    [Serializable]
    public class EditPermissions : IWikiViewModel
    {
        #region Properties

        /// <summary>
        /// Gets the <see cref="PermissionSet"/> to edit.
        /// </summary>
        public PermissionSet PermissionSet { get; private set; }

        /// <summary>
        /// Gets the <see cref="PermissionsHierarchy"/> for the inheritance status.
        /// </summary>
        public PermissionsHierarchy Hierarchy { get; private set; }

        /// <summary>
        /// Gets a value indicating whether or not the permissions being edited are
        /// inherited from a higher object.
        /// </summary>
        public bool PermissionsAreInherited { get; private set; }

        /// <summary>
        /// Gets or sets a value indicating whether or not to modify the original
        /// permissions.
        /// </summary>
        public bool ModifyOriginalPermissions { get; set; }

        #endregion

        #region Constructor

        /// <summary>
        /// Creates a new <see cref="EditPermissions"/> object based on the supplied
        /// <see cref="PermissionSet"/> and whether or not the permissions are inherited.
        /// </summary>
        /// <param name="permissionSet">The permission set to edit.</param>
        /// <param name="inheritedPermissions">A value indicating whether or not the
        /// permissions are inherited from an object higher in the inheritance chain.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="permissionSet"/>
        /// parameter was <c>null</c>.</exception>
        public EditPermissions(PermissionSet permissionSet, bool inheritedPermissions)
        {
            if (permissionSet == null)
            {
                throw new ArgumentNullException("permissionSet");
            }
            PermissionSet = permissionSet;
            PermissionsAreInherited = inheritedPermissions;
            ModifyOriginalPermissions = !inheritedPermissions;
            Hierarchy = new PermissionsHierarchy(permissionSet.ID);
        }

        #endregion
    }
}
